package com.itheima.stock.controller;

import com.itheima.stock.domain.*;
import com.itheima.stock.pojo.StockBusiness;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.resp.PageResult;
import com.itheima.stock.vo.resp.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/quot")
public class StockController {

    @Autowired
    private StockService stockService;

    /**
     * 查询所有股票主业务信息
     *
     * @return
     */
    @GetMapping("/stock/business/all")
    public List<StockBusiness> getAllStockBusiness() {
        return stockService.getAll();
    }

    /**
     * 获取最新国内A股大盘信息(上证+深证)
     *
     * @return
     */
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getInnerMarketInfos() {
        return stockService.getInnerMarketInfos();
    }

    /**
     * 查询最新板块数据，按照交易金额降序取前10
     *
     * @return
     */
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> getStockBlockInfos() {
        return stockService.getStockBlockInfos();
    }

    /**
     * 沪深两市个股涨幅分时行情数据查询，以时间顺序和涨幅查询前10条数据
     *
     * @return
     */
    @GetMapping("/stock/increase")
    public R<List<StockUpdownDomain>> stockIncreaseLimit() {
        return stockService.stockIncreaseLimit();
    }

    /**
     * 分页查询股票涨幅信息
     *
     * @param page     当前页
     * @param pageSize 每页大小
     * @return
     */
    @GetMapping("/stock/all")
    public R<PageResult<StockUpdownDomain>> getPageStockUpDownInfo(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                                                   @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize) {
        return stockService.getPageStockUpDownInfo(page, pageSize);
    }

    /**
     * 功能描述：沪深两市涨跌停分时行情数据查询，查询T日每分钟的涨跌停数据（T：当前股票交易日）
     * 查询每分钟的涨停和跌停的数据的同级；
     * 如果不在股票的交易日内，那么就统计最近的股票交易下的数据
     * map:
     * upList:涨停数据统计
     * downList:跌停数据统计
     *
     * @return
     */
    @GetMapping("/stock/updown/count")
    public R<Map> upDownCount() {
        return stockService.upDownCount();
    }

    /**
     * 通过easyExcel导出指定页的股票涨幅信息
     *
     * @param response 通过响应对象获取输出流，完成excel文件流对象的输出
     * @param page     当前页
     * @param pageSize 每一页大小
     */
    @GetMapping("/stock/export")
    public void exportStockInfo(HttpServletResponse response,
                                @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize) {
        this.stockService.exportStockInfo(response, page, pageSize);
    }

    /**
     * 功能描述：统计国内A股大盘T日和T-1日成交量对比功能（成交量为沪市和深市成交量之和）
     * @return
     */
    @GetMapping("/stock/tradevol")
    public R<Map<String,List>> getStockTradeVolCompare(){
        return stockService.getStockTradeVolCompare();
    }

    /**
     * 统计当前有效时间点下各个涨跌区间的数量
     * @return
     */
    @GetMapping("/stock/updown")
    public R<Map> getStockUpDownSection(){
        return stockService.getStockUpDownSection();
    }

    /**
     * 查询股票的分钟级流水数据-->分时图展示需要
     * @param code
     * @return
     */
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> getStock4Minute(@RequestParam String code){
        return stockService.getStock4Minute(code);
    }

    /**
     * 查询股票的日k线数据
     * @param code
     * @return
     */
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getStock4EvrDay(@RequestParam String code){
        return stockService.getStock4EvrDay(code);
    }
}
